import babelpolyfill from 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import './assets/theme/theme-default/index.css'
import VueRouter from 'vue-router'
import routes from './routes'
import 'font-awesome/css/font-awesome.min.css'
import moment from 'moment'

Vue.use(ElementUI)
Vue.use(VueRouter)

Object.defineProperty(Vue.prototype, 'UPLOADURL', {value: process.env.UPLOAD_URL});
Object.defineProperty(Vue.prototype, 'BASEURL', {value: process.env.BASE_URL});
Object.defineProperty(Vue.prototype, 'moment', {value: moment});

const router = new VueRouter({
    mode:"history",
    routes
})

router.beforeEach((to, from, next) => {
    if (to.path == '/login') {
        sessionStorage.removeItem('user');
        sessionStorage.removeItem('jwt');
    }
    let jwt = sessionStorage.getItem('jwt');
    if (!jwt && to.path != '/login') {
        next({ path: '/login' })
    } else {
        next()
    }
})

new Vue({
    router,
    // store,
    render: h => h(App)
}).$mount('#app')
